<!DOCTYPE html>
<html style="width: 100%; height: 100%;">

<head>
  <meta charset="utf-8">
  <title>翻译集合</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <script src="./layui/layui.js" charset="utf-8"></script>
  <script src="./cookie.js" charset="utf-8"></script>
  <link rel="stylesheet" href="./layui/css/layui.css" media="all">
</head>
<style>
  body {
    background-size: cover;
    background-repeat: no-repeat;
  }
</style>

<body class="layui-bg-black">
  <form class="layui-form" action="" style="margin-top: 5%;">
    <div style="margin: 0px auto; width: 200px; height: 200px;">
      <img src="./image/pngsucai_1922026_4fb2c1.png" style="width: 200px; height: 200px;">
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block"  style="margin: 0px auto; width: 50%;">
        <input type="text" id="title" name="title" required lay-verify="required" placeholder="输入翻译内容" autocomplete="off" class="layui-input">
        <i id="chacha" class="layui-icon layui-icon-close" style="color:#666; position: absolute; font-size: 22px; right: 10px; top: 8px;" onclick="onClear()"></i>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block" style="margin: 0px auto; width: 50%;">
        <input type="radio" name="choose" value="baidu" title="百度翻译" checked>
        <input type="radio" name="choose" value="google" title="谷歌翻译">
        <input type="radio" name="choose" value="deepl" title="AI翻译">
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block" style="margin: 0px auto; width: 100px;">
        <button class="layui-btn" lay-submit lay-filter="formDemo">立即翻译</button>
      </div>
    </div>
  </form>

  <script src="./backdrop.js" charset="utf-8"></script>
  <script src="./clear.js" charset="utf-8"></script>
  <script>
    layui.use('form', function () {
      var form = layui.form;
      //监听提交
      form.on('submit(formDemo)', function (data) {
        layer.msg("正在跳转");
        var r = new RegExp("[a-zA-Z0-9]+");
        var isEn = r.test(data.field.title);
        var txt = encodeURI(data.field.title);
        switch (data.field.choose) {
          case "baidu":
            setTimeout('window.open("https://fanyi.baidu.com/'+(isEn?'#en/zh/':'#zh/en/')+txt+'");', 500);
            break;
          case "google":
            setTimeout('window.open("https://translate.google.cn/#view=home&op=translate'+(isEn?'&sl=en&tl=zh-CN':'&sl=zh-CN&tl=en')+'&text='+txt+'");', 500);
            break;
          case "deepl":
            setTimeout('window.open("https://www.deepl.com/translator#'+(isEn?'en/zh/':'zh/en/')+txt+'");', 500);
            break;
          default:
            break;
        }
        return false;
      });
    });
  </script>
</body>

</html>